<?php 
/* 
* @package TDE Newsletter
* @version: 1.0 
* @last modified: 10:28 AM 06/15/2007
* http://www.topdreamweaverextensions.com
*/
  require_once "./../config.php";
  require_once "./language/".ADMIN_LANGUAGE.".inc.php";
  
  if ($_SESSION["session_username"] == '') 
      header("Location: index.php");
 
  if (isset($_POST["accion"]))
  {
      switch ($_POST["accion"]) 
	  {	  
          case "deleteitem":
              unlink(DATABASE_FOLDER."content_".$_POST["valor1"]);
              break;	  
          default:
		      $showMessage = '<p class="error">'.ALL_MSG_UNKNOWN_ACTION.'</p>';
	  }		  
  }
  
?>
<?php require "./template/top.inc.php" ?>
   
<div id=content>
 <div id=breadCrumb><A><?php echo TXT_NEWSLETTERS; ?></A></div>
 <h2 id=pageName><?php echo TXT_NEWSLETTERS_LIST; ?></h2>

 <?php require "./template/middle.inc.php" ?>
 <div class=story>
<?php  

 $path = DATABASE_FOLDER;
 $d = dir($path);
 while (false !== ($entry = $d->read()))
     if ($entry != '.' && $entry != '..' && !is_dir($path.$entry) && substr($entry,0,8) == 'content_' )
        $fnames[] =  $entry; 
 if (count($fnames) > 0)   
 {
     asort($fnames);
     reset($fnames);
     echo '<table id="tablelist" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><th>ID</th><th>Title</th><th width=1%>&nbsp;</th><th width=1%>&nbsp;</th></tr>';  
     
     foreach ($fnames as $item)
     {
         $fp = fopen(DATABASE_FOLDER.$item, "r");
         $contents = fread ($fp, filesize (DATABASE_FOLDER.$item));
         fclose ($fp);
         $contents = substr($contents,0,strpos($contents,"\n"));        
         echo '<tr>';
         echo '<td>'.base64_decode(substr($item,8)).'</td>'; 
         echo '<td>'.base64_decode($contents).'</td>';
         echo '<td><a href="edit_content.php?id='.substr($item,8).'"><img src="/images//editsmall.gif" border=0 alt="edit item" align=absmiddle></a></td>'; 
	     echo '<td><a href="javascript:deleteItem(\''.substr($item,8).'\');"><img src="/images//deletesmall.gif" border=0 alt="delete item" align=absmiddle></a></td>'; 
	     echo '</tr>';
	 	
     }
     
     echo '</table>';
 }
 else
 {
      echo "No contents yet. Please create a new content.";
 }
          
          
?>
 </div>
</div>		      
<div id=navBar>
 <div class=relatedLinks>
 <h3><?php echo TXT_NEWSLETTERS; ?></h3>
 <ul>
   <LI><A href="edit_content.php"><?php echo TXT_NEWSLETTERS_ADD; ?></A></LI>
  </ul>
  <img src="/images//spacer.gif" height=60% width=1 />
 </div>
</div><br><br>
<?php require "./template/bottom.inc.php" ?>
<script type="text/javascript">
  
  function deleteItem (id)
  {
      if (confirm ('<?php echo ALL_MSG_CONFIRM_DELETE; ?>'))
	  {
	      document.changes.accion.value = "deleteitem";
		  document.changes.valor1.value = id;
		  document.changes.submit();
	  }
  }
</script>